import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';

class PageLoader extends PureComponent {
  render() {
    const { type, retry } = this.props;

    let view;

    switch (type) {
      case 'error':
        view = <div className="text">页面加载失败啦，请退出重试！</div>;
        break;
      case 'timeout':
        view = <div onClick={retry} className="text">加载超时，请点击<span className="retry">重试</span></div>;
        break;
      default:
        view = <div className="spinner" />;
        break;
    }
    return (
      <div className="page-loading">
        {view}
      </div>
    );
  }
}

PageLoader.defaultProps = {
  type: 'loading',
  retry: () => console.log('click retry'),
};

PageLoader.propTypes = {
  type: PropTypes.oneOf(['loading', 'error', 'timeout']),
  retry: PropTypes.func,
};

export default PageLoader;
